package com.wuxb.useFuture;

import java.util.concurrent.*;

public class UseFuture implements Callable<String>{
    private String param;

    public UseFuture(String param){
        this.param = param;
    }

    @Override
    public String call() throws Exception {
        Thread.sleep(3000);
        String result = this.param +"处理完成";
        return result;
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask<String> futureTask = new FutureTask<>(new UseFuture("select user"));

        ExecutorService threadPool = Executors.newFixedThreadPool(2);

        threadPool.execute(futureTask);

        System.out.println("结果: "+futureTask.get());

        threadPool.shutdown();
    }
}
